<?
	include("common.php");

	if(!$loggedin){
		ob_start();
		header("Location: login.php");
	}
	include("pop_header.php");
	$qr1 = mysql_query("SELECT * FROM forum WHERE id=$forum");
	$i = "1";
	$forums = mysql_fetch_object($qr1);
?>
<p><font face=arial size=3>
<b>Start New Thread in <?=$forums->name?></b><br>
<table border="0" cellpadding="10" cellspacing="0" width="85%" align="center">
<tr>
	<td align="left">
<?
	if($step2) {
		$mb = $forum;
		$select_ck_board = mysql_query("SELECT * FROM forum WHERE id='$mb'");
		if(empty($title) or empty($body)) {
			$if_error = "1";
			$input = "1";
		} else if(mysql_num_rows($select_ck_board) == 0) {
			$if_error = "1";
			$input = "2";
		}
		// ERROR HANDLING
		if($if_error == "1") {
			if($input == "1") {
				$message = "<b>A required field was left blank.</b><br><br>Please use the back button on your browser, or <a href=\"javascript:history.back(1)\">click here</a>, to return to the previous form. You must fill in the \"<b>Subject</b>\" and \"<b>Body</b>\" fields in order to properly create a new thread.";
			}
			if($input == "2") {
				$message = "<b>Forum does not exist.</b><br><br>The forum you have attempted to post to does not exist in our system. Please return to the <a href=\"$siteurl/index.php\">forum home</a> to select a valid forum.";
			}
			include("errormsg.php");
		} else {
			// SET TIME & DATE
			$date = time()+$timeadjust;

			// INSERT BOARD
			$sql = "INSERT INTO thread SET mb='$mb',uid='$myuid',title='$title',body='$body',timestamp='$date'";
			mysql_query ($sql) or die( mysql_error() );
?>
			<table border="0" cellpadding="20" cellspacing="0" width="100%" height="100%">
			<tr>
				<td width="100%">
					<table border="0" cellpadding="8" cellspacing="0" width="100%" bgcolor="#F5F5F5">
					<tr>
						<td width="100%"><meta http-equiv="refresh" content="2; url=<?=$siteurl?>/forum.php?forum=<?=$mb?>"><div align="center"><font face="verdana, arial, helvetica, sans-serif" size="2"><b>Your post is being processed... You will be redirected to the thread display shortly.</b></font></div></td>
					</tr>
					</table>
				</td>
			</tr>
			</table>
<?
		}
	} else {
?>
		<font face="arial, verdana, helvetica, sans-serif" size=\"2\">
		To post a new thread on the <?=$sitename?> forum please fill out the following form below. All fields 
		are required to be properly filled out with information. Please be aware that HTML tags are not 
		allowed.</font></div>
		<br><br>
		<form method="post"">
		<input type="hidden" name="forum" value="<?=$forum?>">
		<table border="0" cellpadding="1" cellspacing="0" width="100%">
		<tr>
			<td width="100%" colspan="2">
				<table border="0" cellpadding="8" cellspacing="1" width="100%" height="34" style='border: 1px solid #000000;background-color:#e5e5e5;'>
				<tr>
					<td>
						<font face="verdana, arial, helvetica, sans-serif" size="2" color="#000000"><b>New Thread for '<?=$forums->name?>'</b></font></td>
					</td>
				</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td width="100%">
				<table border="0" cellpadding="8" cellspacing="1" width="100%">
				<tr bgcolor="#F5F5F5">
					<td NOWRAP><font face="verdana, arial, helvetica, sans-serif" size="2"><b>Subject:</b></font></td>
					<td width="100%"><input type="text" name="title" size="40"></td>
				</tr>
				<tr bgcolor="#FAFAFA">
					<td valign="top" NOWRAP><font face="verdana, arial, helvetica, sans-serif" size="2"><b>Body:</b><font size="1"><br>(50,000 maximum characters)</font></font></td>
					<td width="100%"><textarea name="body" cols="63" rows="15" tabindex="2"></textarea></td>
				</tr>
				<tr bgcolor="#F5F5F5">
					<td width="100%" align="right" colspan="2"><input type="submit" name="step2" value="Submit Thread"></td>
				</tr>
				</table>
			</td>
		</tr>
		</table>
		</form>
<?
	}
?>
	</td>
</tr>
</table>
</font></p>
<?
	include("pop_footer.php");
?>